#include <std.h>
#include <pio.h>
#include <system.h>
#include <error.h>
#include <type.h>

#define STANDARD_INFORMATION 0x10
#define ATTRIBUTE_LIST 0x20
#define FILE_NAME 0x30
#define VOLUME_VERSION 0x40 //NT
#define OBJECT_ID 0x40 //2000
#define SECURITY_DESCRIPTOR 0x50
#define VOLUME_NAME 0x60
#define VOLUME_INFORMATION 0x70
#define DATA 0x80
#define INDEX_ROOT 0x90
#define INDEX_ALLOCATION 0xa0
#define BITMAP 0xb0
#define SYMBOLIC_LINK 0xc0 //NT
#define REPARSE_POINT 0xc0 //2000
#define EA_INFORMATION 0xd0
#define EA 0xe0
#define PROPERTY_SET 0xf0 //NT
#define LOGGED_UTILITY_STREAM 0x100 //2000

struct STANDARD_INFORMATION_struct	{
	u64 ctime; //creation
	u64 atime; //alteration
	u64 mtime; //MFT changed
	u64 rtime; //Read
	u32 DOSfileperm;
	u32 maxver;
	u32 ver;
	u32 classid;
	u32 ownerid2k;
	u32 securityid2k;
	u64 quotac2k;
	u64 usn2k; //Update sequence number
};

/*Owner Id
Owner Id of the user owning the file. This Id is a key in the $O and $Q Indexes of the file $Quota. If
zero, then quotas are disabled.*/

//File permissions:

#define PERM_R 1
#define PERM_HID 2
#define PERM_SYS 4
#define PERM_ARCH 0x20
#define PERM_DEV 0x40
#define PERM_NORM 0x80
#define PERM_TEMP 0x100
#define PERM_SPARSEFILE 0x200
#define PERM_REPARSEPOINT 0x400
#define PERM_COMP 0x800
#define PERM_OFFLINE 0x1000
#define PERM_NCONTENTINDEXED 0x2000
#define PERM_ENCRYPTED 0x4000

struct ATTRIBUTE_LIST_struct	{
	u32 type;
	u16 rec_len;
	u8 name_len;
	u8 offset_name;
	u64 VCN_start;
	u64 base_file_ref;
	u16 attrib_id;
	u8 *name;		//String of length 2*name_len;
};

struct FILE_NAME_struct	{
	u64 file_ref_parent;
	u64 ctime;
	u64 atime;
	u64 mtime;
	u64 rtime;
	u64 alloc_size;
	u64 real_size;
	u32 flags;
	u32 ea_reparse;
	u8 filename_len;
	u8 *filename; //String of length 2*filename_len
};

#define FLAGS_R 1
#define FLAGS_HID 2
#define FLAGS_SYS 4
#define FLAGS_ARCH 0x20
#define FLAGS_DEV 0x40
#define FLAGS_NORM 0x80
#define FLAGS_TEMP 0x100
#define FLAGS_SPARSEFILE 0x200
#define FLAGS_REPARSEPOINT 0x400
#define FLAGS_COMP 0x800
#define FLAGS_OFFLINE 0x1000
#define FLAGS_NCONTENTINDEXED 0x2000
#define FLAGS_ENCRYPTED 0x4000
#define FLAGS_DIRECTORY 0x10000000
#define FLAGS_INDEX_VIEW 0x20000000

struct OBJECT_ID_struct	{
	u8 guid_object_id[16];
	u8 guid_birth_volume_id[16];
	u8 guid_birth_object_id[16];
	u8 guid_domain_id[16];
};

struct SECURITY_DESCRIPTOR	{
	u8 revision;
	u8 padding;
	u16 control_flags;
	u32 usersidoff;
	u32 groupsidoff;
	u32 SACL_off;
	u32 DACL_off;
};

struct VOLUME_INFORMATION_struct	{
	u64 resvd;
	u8 major_rev;
	u8 minor_rev;
	u16 flags;
	u32 resvd;
};

#define VOLFLAG_DIRTY 1
#define VOLFLAG_RESIZELOG 2
#define VOLFLAG_UPGRADE_MOUNT 0x4
#define VOLFLAG_NT4MOUNT 0x8
#define VOLFLAG_DELUSN 0x10
#define VOLFLAG_REPAIROBJID 0x20
#define VOLFLAG_CHKDSKMOD 0x8000

/*Versions:
Windows NT 1.2
Windows 2000 3.0
Windows XP 3.1 */

struct INDEX_ROOT_struct	{
	u32 attrib_type;
	u32 collation_rule;
	u32 size_index_alloc;
	u8 clus_per_indexrec;
	u8 padding[3];
}__attribute__((packed));

struct INDEX_HEADER_struct	{
	u32 first_index_off;
	u32 total_size;
	u32 alloc_size;
	u8 flags;
	u8 padding[3];
}__attribute__((packed));

